package com.dynamic.idea.quick.develop.plugin.utils;

import com.dynamic.idea.quick.develop.plugin.constants.QuickDevelopConstants;
import org.apache.commons.lang3.StringUtils;

public class FilePathUtils {

    /**
     * 连接路径
     * @param path
     * @param childPath
     * @return
     */
    public static String connectPath(String path,String childPath){
        if (StringUtils.isBlank(path)){
            return null;
        }
        if (StringUtils.isBlank(childPath)){
            return path;
        }
        while (StringUtils.endsWith(path, QuickDevelopConstants.FILE_SEPARATOR)){
            path=StringUtils.removeEnd(path,QuickDevelopConstants.FILE_SEPARATOR);
        }

        while (StringUtils.startsWith(childPath, QuickDevelopConstants.FILE_SEPARATOR)){
            childPath=StringUtils.removeStart(childPath,QuickDevelopConstants.FILE_SEPARATOR);
        }
        return path+QuickDevelopConstants.FILE_SEPARATOR+childPath;
    }



    /**
     * 包名转为路径
     * @param packageName
     * @return
     */
    public static String package2Path(String packageName){
        if (StringUtils.isBlank(packageName)){
            return null;
        }
        return StringUtils.replace(StringUtils.trim(packageName),".", QuickDevelopConstants.FILE_SEPARATOR);
    }
}
